package com.tanhua.server.controller;

import com.tanhua.commons.utils.UserHolder;
import com.tanhua.server.service.BaiduService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
@Slf4j
public class BaiduController {
    @Autowired
    private BaiduService baiduService;

    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map) {
        log.info("66666666666:{}", map);
        Long userId = UserHolder.getUserId();
        double latitude = Double.valueOf(map.get("latitude").toString());
        double longitude = Double.valueOf(map.get("longitude").toString());
        String addrStr = map.get("addrStr").toString();
        baiduService.saveLocation(userId, latitude, longitude, addrStr);
        return ResponseEntity.ok(null);
    }

}
